#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
using LL = long long;
const int N = 1510, INF = 0x3f3f3f3f;
int n, root;
LL dp[N][3], w[N];
bool flag[N];
vector<int> g[N];

// 0: 被子节点监视
// 1：被自己监视
//2：被父节点监视

void dfs(int u)
{
    dp[u][0] = INF, dp[u][1] = w[u], dp[u][2] = 0;
    dp[u][1] = w[u];
    // dp[u][0] = dp[ch][1] + min(dp[ch][1], dp[ch][)
    for(auto nd: g[u])
    {
        dfs(nd);
        dp[u][2] += min(dp[nd][1], dp[nd][0]);
        dp[u][1] += min({dp[nd][1], dp[nd][0], dp[nd][2]});
    }
    for(auto nd: g[u])
        dp[u][0] = min(dp[u][0], dp[u][2] - min(dp[nd][1], dp[nd][0]) + dp[nd][1]);
    
}


int main()
{
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int h, num;
        cin >> h;
        cin >> w[h] >> num;
        for(int i = 0; i < num; ++i)
        {
            int tmp;
            cin >> tmp;
            g[h].push_back(tmp);
            flag[tmp] = true;
        }
    }
    for(int i = 1; i <= n; ++i)
        if(!flag[i])
        {
            root = i;
            break;
        }
    
        dfs(root);
        cout << min(dp[root][1], dp[root][0]) << endl;
    return 0;
}